home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Includes / UTECommands.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  15.0 KB  |  445 lines  |  [TEXT/MPS ]

  1. // UTECommands.h
  2. // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UTECOMMANDS__
  6. #define __UTECOMMANDS__
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UCOMMAND__
  11. #include "UCommand.h"
  12. #endif
  13.  
  14. // Toolbox
  15.  
  16. #ifndef __TEXTEDIT__
  17. #include <TextEdit.h>
  18. #endif
  19.  
  20.  
  21. //----------------------------------------------------------------------------------------
  22. // Forward and external class declarations. 
  23. //----------------------------------------------------------------------------------------
  24.  
  25. class TEditText;
  26. class TTEView;
  27.  
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // TTECommand: A command that adds characters to, or delete characters from, a TEView 
  31. //----------------------------------------------------------------------------------------
  32.  
  33. class TTECommand : public TCommand
  34. {
  35.     MA_DECLARE_CLASS;
  36.     
  37. public:
  38.     TTEView* fTEView;                            // The TEView operated on
  39.     
  40.     TEditText*    fEditText;                        // The TEditText operated on. This command
  41.                                                 // class can be used to modify either TTEView
  42.                                                 // or TEditText.
  43.  
  44.     TEHandle fHTE;                                // same as fTEView's fHTE; duplicated for
  45.                                                 // code efficiency 
  46.  
  47.     short fOldStart;                            // The beginning position of the selection
  48.                                                 // at the moment just before the command
  49.                                                 // was done. 
  50.  
  51.     short fOldEnd;                                // The end position of the selection at
  52.                                                 // the moment just before the command was
  53.                                                 // done. 
  54.  
  55.     Handle fOldText;                            // If fOldStart = fOldEnd, i.e., if old
  56.                                                 // selection had been an insertion CPoint,
  57.                                                 // this will be NULL. Otherwise, provides a
  58.                                                 // temporary home for the characters
  59.                                                 // comprising the old selection
  60.                                
  61.     CStr255    fOldStaticText;                        // Temporary home for TStaticText contents.
  62.                                                 // Note: TEditText derives from TStaticText
  63.     
  64.     StScrpHandle fOldStyles;
  65.  
  66.     short fNewStart;                            // The beginning location in the Text of
  67.                                                 // the new text that is added by the
  68.                                                 // command, if any. 
  69.  
  70.     short fNewEnd;                                // The ending location in the Text of the
  71.                                                 // new text that is added by the command,
  72.                                                 // if any. 
  73.  
  74.     Handle fNewText;                            // A Handle to the characters added by the
  75.                                                 // command 
  76.  
  77.     StScrpHandle fNewStyles;
  78.  
  79.     Handle fPadding;                            // Handle to fill size between new and
  80.                                                 // old. This insures that we can always
  81.                                                 // undo and redo. 
  82.  
  83.     short fTextPad;                                // Size difference between New and Old
  84.                                                 // text 
  85.  
  86.     long fStylePad;                                // Size difference between New and Old
  87.                                                 // styles 
  88.  
  89.  
  90.     //------------------------------------------------------------------------------------
  91.     // Initialize and Free 
  92.     //------------------------------------------------------------------------------------
  93.  
  94.     TTECommand();
  95.         // Constructor
  96.         
  97.     void ITECommand(TTEView* itsTEView, CommandNumber itsCommandNumber, Boolean itsSaveText);
  98.         // Initialize the command; if unsuccessful, exit is via Failure mechanism. 
  99.         
  100.     void ITECommand(TEditText* itsEditText, CommandNumber itsCommandNumber, Boolean itsSaveText);
  101.         // Overload initializer to work with TEditText views.
  102.  
  103.     virtual ~TTECommand();
  104.         // Free the text handles holding information needed for Undo/ Redo, then Inherited::Free.
  105.  
  106.  
  107.     //------------------------------------------------------------------------------------
  108.     // Command execution phase overrides 
  109.     //------------------------------------------------------------------------------------
  110.  
  111.     virtual void DoIt();
  112.         // Focuses, then calls DoMainFunction 
  113.  
  114.     virtual void RedoIt();
  115.         // Focuses, calls RestoreSelection to get selection right, then calls
  116.         // DoMainFunction to reinstate the changes done in DoIt which were undone by a
  117.         // preceding UndoIt 
  118.  
  119.     virtual void UndoIt();
  120.         // Focuses, then dispatches to RemoveAdditions, ReviveDeletions, and
  121.         // RestoreSelection to accomplish the Undo 
  122.  
  123.     virtual void SetupDependencies(); // Override
  124.         // Overridden to make this command a dependent of its fTEView. 
  125.  
  126.     virtual void DoUpdate(ChangeID theChange,
  127.                                  TObject* changedObject, 
  128.                                  TObject* changedBy,
  129.                                  TDependencySpace* dependencySpace); // Override
  130.         // If the fTEView is closed, commit this command  
  131.  
  132.     //----------------------------------------------------------------------------------------
  133.     // Command execution - Restoration of Selection -- called in both UNDO and REDO phases
  134.     //----------------------------------------------------------------------------------------
  135.  
  136.     virtual void RestoreSelection();
  137.         // Set the Selection to be what it was just before the DO phase of the command was
  138.         // performed 
  139.  
  140.     virtual void PrepareForUndoRedo(); // override
  141.         // Make the command context visible for undo/redo. 
  142.     
  143.     virtual void RevealUndoRedo(); // override
  144.         // Make this context visible after undo/redo. 
  145.  
  146.  
  147.     //------------------------------------------------------------------------------------
  148.     // Command execution - steps in DO and REDO phases 
  149.     //------------------------------------------------------------------------------------
  150.  
  151.     virtual void AssureTEView();
  152.         // Guarantee that a TEView exists when the command knows about a TEditText.
  153.         
  154.     virtual void ForgetTEView();
  155.         // Forget references to the TEView when the command knows about a TEditText.
  156.         
  157.     virtual void DoPostProcess();
  158.         // Put TEView/TEdit text fields in post-process state.
  159.         
  160.     virtual void BanishOldText();
  161.         // Remove text that was selected at the outset of the Do phase 
  162.  
  163.     virtual void InstallNewText();
  164.         // Install the new text 
  165.  
  166.     virtual void DoMainFunction();
  167.         // Forwards to the relevant methods for Do and Redo phases 
  168.  
  169.  
  170.     //------------------------------------------------------------------------------------
  171.     // Command execution - steps in UNDO phase 
  172.     //------------------------------------------------------------------------------------
  173.  
  174.     virtual void RemoveAdditions();
  175.         // Remove any characters which were added by the DO phase of the command 
  176.  
  177.     virtual void ReviveDeletions();
  178.         // Bring back the characters which were removed during the DO phase 
  179.  
  180. };
  181.  
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // TTECutCopyCommand: Command for handling Cut & Copy for the TEView.
  185. //----------------------------------------------------------------------------------------
  186.  
  187. class TTECutCopyCommand : public TTECommand
  188. {
  189.     MA_DECLARE_CLASS;
  190.     
  191. public:
  192.     Boolean fClipCreated;                        // Clipboard view created OK 
  193.  
  194.  
  195.     //------------------------------------------------------------------------------------
  196.     // Creation and Destruction 
  197.     //------------------------------------------------------------------------------------
  198.  
  199.     TTECutCopyCommand();
  200.         // Empty constructor to satisfy compiler.
  201.         
  202.     void ITECutCopyCommand(TTEView* itsTEView, CommandNumber itsCommandNumber);
  203.  
  204.         // Initializes the command 
  205.  
  206.     virtual ~TTECutCopyCommand();
  207.         // Free the command 
  208.  
  209.  
  210.     //------------------------------------------------------------------------------------
  211.     // Command execution 
  212.     //------------------------------------------------------------------------------------
  213.  
  214.     virtual void DoIt();
  215.         // Launches a TEView for installation in the Clipboard, then calls DoMainFunction
  216.         // 
  217.  
  218.     virtual void ReviveDeletions();
  219.         // Bring back the characters which were removed during the DO phase; called during
  220.         // UNDO phase 
  221.  
  222. };
  223.  
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // TTEPasteCommand: Command that handles Pasting for the TEView. 
  227. //----------------------------------------------------------------------------------------
  228.  
  229. class TTEPasteCommand : public TTECommand
  230. {
  231.     MA_DECLARE_CLASS;
  232.     
  233. public:
  234.     //------------------------------------------------------------------------------------
  235.     // Initialization 
  236.     //------------------------------------------------------------------------------------
  237.  
  238.     TTEPasteCommand();
  239.         // Empty constructor to satisfy compiler.
  240.     virtual ~TTEPasteCommand();
  241.         // Destructor
  242.         
  243.     void ITEPasteCommand(TTEView* itsTEView);
  244.         // Initialize the command; if unsuccessful, signalled by Failure mechanism 
  245.  
  246. };
  247.  
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // TTEStyleCommand: Command for applying a new style to the TEView.
  251. //----------------------------------------------------------------------------------------
  252.  
  253. class TTEStyleCommand : public TTECommand
  254. {
  255.     MA_DECLARE_CLASS;
  256.     
  257. public:
  258.     //------------------------------------------------------------------------------------
  259.     // These two fields are only used in non-styled TextEdit records 
  260.     //------------------------------------------------------------------------------------
  261.  
  262.     short fMode;                                // Mode for style change 
  263.  
  264.     TextStyle fOldTextStyle;                    // The original text style 
  265.  
  266.     TextStyle fNewTextStyle;                    // What we're replacing it with 
  267.  
  268.  
  269.     //------------------------------------------------------------------------------------
  270.     // Initialization 
  271.     //------------------------------------------------------------------------------------
  272.  
  273.     TTEStyleCommand();
  274.         // Empty constructor to satisfy compiler.
  275.     virtual ~TTEStyleCommand();
  276.         // Destructor
  277.         
  278.     void ITEStyleCommand(TTEView* itsTEView,
  279.                                         const TextStyle& itsNewStyle,
  280.                                         CommandNumber itsCommandNumber,
  281.                                         short itsMode);
  282.         // Initialize the command; if unsuccessful, signalled by Failure mechanism 
  283.  
  284.  
  285.     //------------------------------------------------------------------------------------
  286.     // Command execution 
  287.     //------------------------------------------------------------------------------------
  288.  
  289.     virtual void InstallOneStyle(const TextStyle& newStyl);
  290.         // Installs one style over entire record - for use with old TextEdit 
  291.  
  292.     virtual void InstallManyStyles(StScrpHandle newStyls);
  293.         // Installs styles over selection range - for use with styled TextEdit 
  294.  
  295.     virtual void DoIt();
  296.         // Applies style to selection range 
  297.  
  298.     virtual void UndoIt();
  299.         // Undoes the action performed by DoIt. 
  300.  
  301.     virtual void RedoIt();
  302.         // Calls DoIt. 
  303.  
  304. };
  305.  
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // TTETypingCommand: The command that handles typing in a TEView.
  309. //----------------------------------------------------------------------------------------
  310.  
  311. class TTETypingCommand : public TTECommand
  312. {
  313.     MA_DECLARE_CLASS;
  314.     
  315. public:
  316.     //------------------------------------------------------------------------------------
  317.     // Creation and destruction 
  318.     //------------------------------------------------------------------------------------
  319.  
  320.     TTETypingCommand();
  321.         // Empty constructor to satisfy compiler.
  322.         
  323.     void ITETypingCommand(TTEView* itsTEView, const CStr2& itsFirstCh);
  324.         // Initialize the command; if not successful, exit is via Failure mechanism 
  325.  
  326.     virtual ~TTETypingCommand();
  327.         // Deallocate the command and dependent structures 
  328.  
  329.  
  330.     //------------------------------------------------------------------------------------
  331.     // Command processing 
  332.     //------------------------------------------------------------------------------------
  333.  
  334.     virtual void DoNormalChar(const CStr2& ch);
  335.         // Handle any typed character[s] except a backspace 
  336.  
  337.     virtual void BkSpcLeft(Handle theText, short curStart);
  338.         // Handle backspace to the left of the original selection 
  339.  
  340.     virtual void BkSpcRight(Handle theText, short curStart);
  341.         // Handle backspace to the right of the original selection 
  342.  
  343.     virtual void FwdDelete(Handle theText, short curStart, short curEnd);
  344.  
  345.  
  346.     //------------------------------------------------------------------------------------
  347.     // Handle forward delete 
  348.     //------------------------------------------------------------------------------------
  349.  
  350.     virtual void AddCharacter(const CStr2& ch);
  351.         // Add character[s] to an already-launched TETypingCommand 
  352.  
  353.     virtual void DoIt();
  354.         // First processing for command; adds first character 
  355.  
  356.     virtual void RedoIt();
  357.         // Handles undoing forward backspace 
  358.  
  359.     virtual void UndoIt();
  360.         // Process undo typing 
  361.  
  362.     virtual void CompleteTyping();
  363.         // Mark as no more typing allowed and fix up style scrap, if any 
  364.  
  365.     //------------------------------------------------------------------------------------
  366.     // data members 
  367.     //------------------------------------------------------------------------------------
  368. public:
  369.     Boolean fCompleted;                            // Indicates whether further keystrokes
  370.                                                 // will be extensions to this command
  371.                                                 // (false) or whether the command has
  372.                                                 // already been completed (true) 
  373.  
  374.     CStr2 fFirstChar;                            // First character[s] typed 
  375. };
  376.  
  377. #if qDrag
  378.  
  379. //----------------------------------------------------------------------------------------
  380. // TTEDragDropCommand: Command that handles a drag or drop text operation.
  381. //----------------------------------------------------------------------------------------
  382.  
  383. class TTEDragDropCommand : public TTECommand
  384. {
  385.     MA_DECLARE_CLASS;
  386.     
  387. public:
  388.     TTEDragDropCommand();                
  389.         // default constructor
  390.     virtual ~TTEDragDropCommand();
  391.         // Destructor
  392.     
  393.     void ITEDragDropCommand(TTEView    *itsTEView, CommandNumber itsCommandNumber);    // overloaded initializer
  394.     
  395.     void ITEDragDropCommand(TEditText *itsEditText, CommandNumber itsCommandNumber);
  396.         
  397.     void DoMainFunction();
  398.         // Override. Don't banish the old text.
  399.     
  400.     virtual void SetNewText(Handle newText, StScrpHandle newStyles);
  401.         // set text to be installed in the target TTEView
  402.         
  403.     virtual void SetNewStart(short newStart);
  404.         // set the location for the new text
  405.         
  406.     virtual void InstallNewText();
  407.         // OVERRIDE
  408.                 
  409. }; // class TTEDragDropCommand
  410.  
  411. //----------------------------------------------------------------------------------------
  412. // TTEDragMoveCommand: Command that handles moving text within a view as a result of
  413. // a drag
  414. //----------------------------------------------------------------------------------------
  415.  
  416. class TTEDragMoveCommand : public TTECommand
  417. {
  418.     MA_DECLARE_CLASS;
  419.     
  420. public:
  421.     
  422.     TTEDragMoveCommand();
  423.         // Constructor
  424.         
  425.     void ITEDragMoveCommand(TTEView *itsTEView, CommandNumber itsCommandNumber, short newStart);
  426.     
  427.     void ITEDragMoveCommand(TEditText *itsEditText, CommandNumber itsCommandNumber, short newStart);
  428.     
  429.     virtual ~TTEDragMoveCommand();
  430.     
  431.     virtual void InstallNewText();
  432. };
  433.  
  434. #endif // qDrag
  435.     
  436. //----------------------------------------------------------------------------------------
  437. // Global function declarations
  438. //----------------------------------------------------------------------------------------
  439.  
  440. void DumpTTECommand(TTECommand* theTTECommand);
  441.     // writes TTECommand info out to Debug window 
  442.  
  443. #endif
  444.  
  445.